//
//  MainTableViewController.m
//  MyiOS
//
//  Created by zhuyechao on 18/04/2017.
//  Copyright © 2017 zyc. All rights reserved.
//

#import "MainTableViewController.h"
#import "MainTableCellModel.h"

@interface MainTableViewController ()

@property (nonatomic, strong) NSMutableArray<MainTableCellModel *> *data;

@end

@implementation MainTableViewController {
    NSString *cellReuseIdentifier;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self doInit];
}

- (void)doInit {
    self.title = @"My iOS";
    cellReuseIdentifier = @"main_cell";
    self.data = [NSMutableArray array];
    [_data addObject:[[MainTableCellModel alloc] initWithDict:@{
                                                                @"title":@"JSContext",
                                                                @"controller":@"JSViewController"}]];
//    [_data addObject:[[MainTableCellModel alloc] initWithDict:@{
//                                                                @"title":@"测试 2"}]];
//    [_data addObject:[[MainTableCellModel alloc] initWithDict:@{
//                                                                @"title":@"测试 3"}]];
//    [_data addObject:[[MainTableCellModel alloc] initWithDict:@{
//                                                                @"title":@"测试 4"}]];
//    [_data addObject:[[MainTableCellModel alloc] initWithDict:@{
//                                                                @"title":@"测试 5"}]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = self.data[indexPath.row].cellTitle;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    MainTableCellModel *model = _data[indexPath.row];
    UIViewController *vc = [[NSClassFromString(model.controllerClass) alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
